# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html

#import time
#import json
#import codecs
#import os.path
import pymysql

class DemotianqiPipeline(object):
	def process_item(self, item, spider):
		db = pymysql.connect("localhost","root","123456","demo" )
		cursor = db.cursor()
		sql = "insert into tianqi(shijian,tianqi,qiWen,fengXiang1,fengXiang2,fengXiangJiBie) values('%s','%s','%s','%s','%s','%s')" %(item['shijian'][0],item['tianqi'][0],item['qiWen'][0],item['fengXiang1'][0],item['fengXiang2'][0],item['fengXiangJiBie'][0])
		try:
			# 执行sql语句
			cursor.execute(sql)
			# 执行sql语句
			db.commit()
		except:
			# 发生错误时回滚
			db.rollback()
		# 关闭数据库连接
		db.close()
		return item
